<?php
require_once("../driver/tableLocation.php");
require_once("../driver/drive.php");
include_once("../driver/tableLocation.php");
include_once("../global/global_function.php");
class classRHandle
{
    public function readAllClass()
    {
        $tablename = tableLocation::classTable();
        $sql = "select * from $tablename order by id desc";
        $result = drive::get_all_rows($sql);
        return $result;
    }

    public function readClassById($id)
    {
        $tablename = tableLocation::classTable();
        $sql = "select * from $tablename where id=$id";
        $result = drive::get_all_rows($sql);
        return $result;
    }
    public function get_all_data($orderby="", $limit="")
    {
        $tablename = tableLocation::classTable();
        $sql = "select * from $tablename $orderby $limit";
        return drive::get_all_rows($sql);
    }
    public function get_class_num($array='')
    {
        $tablename = tableLocation::classTable();
        $sql = get_select_sql($tablename, "count(*)", $array);
        $result = drive::get_one_value($sql);
        return $result;
    }
    public function get_some_data($array, $orderby='', $limit='')
    {
        $tablename = tableLocation::classTable();
        $sql = "select * from $tablename where ";
        $first=0;
        foreach($array as $key=>$value)
        {
            if($first==0)
            {
                $sql .= "`$key`='$value' ";
                $first=1;
            }
            else
            {	
                $sql .= "and `$key`='$value'";
            }
        }
        $sql .= " $orderby $limit";
        return drive::get_all_rows($sql);
    }
    public function searchByKeyword($keyword, $limit='')
    {
    		$table = tableLocation::classTable();
    		$sql = "select * from $table where name like '%$keyword%' or monitorid like '%$keyword%' or teacherid like '%$keyword%' order by id desc $limit";
    		return drive::get_all_rows($sql);
    }

}
?>